package com.itheima.mp.controller;

import cn.hutool.core.bean.BeanUtil;
import com.itheima.mp.domain.po.User;
import com.itheima.mp.domain.vo.UserVO;
import com.itheima.mp.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 张文接
 * @version 1.0
 * @createTime 2024/8/13 09:44
 */
@Api(tags = "缓存测试")
@Slf4j
@RestController
@RequestMapping("/cache")
public class CacheController {
    @Resource
    private UserService userService;

    @GetMapping("/{id}")
    @ApiOperation("根据id查询用户")
    public UserVO findById(@PathVariable Long id) {
        log.info("开始访问数据库");
        User user = userService.queryUserById(id);
        return BeanUtil.copyProperties(user, UserVO.class);
    }
}
